package com.dance.netty.netty.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.ServerSocketChannel;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * 通道初始化
 */
public class HttpServerInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        // 向管道加入处理器
        ChannelPipeline pipeline = socketChannel.pipeline();
        // 加入一个Netty提供的 HttpServerCodec codec => [coder - decoder]
        /*
        HttpServerCodec 是Netty提供的处理HTTP的
         */
        pipeline.addLast("MyHttpServer", new HttpServerCodec());

        // 添加自己的处理器
        pipeline.addLast("MyHandler", new HttpServerHandler());
    }
}
